<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	word		= Request("findWord")
	writeID		= Request("findWriteID")
	
	setUser	= Request("setUser")	'권한 위임

	SQLTitle = "-- ■■■■ 결재 장기보관함 그리드 List up ■■■■"	
	
	userId		= Request.Cookies("S_uid")
	
	'## 검색조건에 따른 조건절 만들기 
	If word <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " (A.subjects LIKE '%" & word & "%' OR A.contents LIKE '%" & word & "%') "
	End If 
	if setUser = "" then 
		If writeID <> "" Then 
			If addSql <> "" Then addSql = addSql & " AND "
			addSql = " A.writeID = '" & writeID & "' "
		End If 
	else
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = " A.writeID = '" & setUser & "' "		 
	end if 

	If addSql <> "" Then addSql = " AND " & addSql
	addSql = " WHERE (B.userId='" & userId & "' or A.tmpFlag='T') "  & addSql

	SQL = "SELECT A.apprYear, A.apprSeq, A.writeID, C.userNm writeNm, " & _
			"					 A.subjects, CONVERT(varchar(16), A.writeDt, 121) writeDt, CONVERT(varchar(16), A.modDt, 121) modDt, T.tailCnt, " & _
			"					CASE WHEN A.tmpFlag = 'T' THEN '임시보관' ELSE '장기보관' END keepStatus " & _
			"		FROM tblWorkAppr A " & _
			"				LEFT JOIN tblWorkApprKeep B ON A.apprYear=B.apprYear AND A.apprSeq=B.apprSeq " & _
			"				LEFT JOIN tblUser C ON A.writeID=C.userId " & _ 
			"				LEFT JOIN (SELECT apprYear, apprSeq, ISNULL(count(*),'') tailCnt FROM tblWorkApprTail WHERE flag='Y' GROUP BY apprYear, apprSeq) T ON A.apprYear=T.apprYear AND A.apprSeq=T.apprSeq " & addSql & _
			"	ORDER BY A.writeDt DESC"
			
	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<KeepList>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
			
			Response.write "	<KeepWork>" & vbcrlf
				Call mkXMLNode("apprYear", rs("apprYear"), 2)
				Call mkXMLNode("apprSeq", rs("apprSeq"), 2)
				Call mkXMLNode("writeID", rs("writeID"), 2)
				Call mkXMLNode("writeNm", rs("writeNm"), 2)
				Call mkXMLNode("subjects", rs("subjects"), 2)
				Call mkXMLNode("keepStatus", rs("keepStatus"), 2)
				Call mkXMLNode("writeDt", right(rs("writeDt"),11), 2)
				Call mkXMLNode("modDt", right(rs("modDt"),11), 2)
				Call mkXMLNode("tailCnt", rs("tailCnt"), 2)
			Response.write "	</KeepWork>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</KeepList>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>